<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="质检id" prop="qualityId">
        <el-input v-model="queryParams.qualityId" placeholder="请输入质检id" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="外观质量检查" prop="qualityAppearance">
        <el-input v-model="queryParams.qualityAppearance" placeholder="请输入外观质量检查" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="尺寸大小检查" prop="qualityDimensiona">
        <el-input v-model="queryParams.qualityDimensiona" placeholder="请输入尺寸大小检查" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="强度和耐性检查" prop="qualityStrength">
        <el-input v-model="queryParams.qualityStrength" placeholder="请输入强度和耐性检查" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="织物结构检查" prop="qualityFabric">
        <el-input v-model="queryParams.qualityFabric" placeholder="请输入织物结构检查" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="成分检查" prop="qualityComponent">
        <el-input v-model="queryParams.qualityComponent" placeholder="请输入成分检查" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="质检数量" prop="qualityRawNum">
        <el-input v-model="queryParams.qualityRawNum" placeholder="请输入质检数量" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="不合格数量" prop="qualityUnqualifiedNum">
        <el-input v-model="queryParams.qualityUnqualifiedNum" placeholder="请输入不合格数量" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="化学物质检查" prop="qualityChemical">
        <el-input v-model="queryParams.qualityChemical" placeholder="请输入化学物质检查" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
          v-hasPermi="['raw:raw:add']">新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate"
          v-hasPermi="['raw:raw:edit']">修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete"
          v-hasPermi="['raw:raw:remove']">删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
          v-hasPermi="['raw:raw:export']">导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="rawList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="质检详情" align="center" prop="qualityRawId" />
      <el-table-column label="质检id" align="center" prop="qualityId" />
      <el-table-column label="外观质量检查" align="center" prop="qualityAppearance" />
      <el-table-column label="尺寸大小检查" align="center" prop="qualityDimensiona" />
      <el-table-column label="强度和耐性检查" align="center" prop="qualityStrength" />
      <el-table-column label="织物结构检查" align="center" prop="qualityFabric" />
      <el-table-column label="成分检查" align="center" prop="qualityComponent" />
      <el-table-column label="质检数量" align="center" prop="qualityRawNum" />
      <el-table-column label="不合格数量" align="center" prop="qualityUnqualifiedNum" />
      <el-table-column label="化学物质检查" align="center" prop="qualityChemical" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
            v-hasPermi="['raw:raw:edit']">修改</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
            v-hasPermi="['raw:raw:remove']">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <!-- 添加或修改原料质检对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="质检id" prop="qualityId">
          <el-input v-model="form.qualityId" placeholder="请输入质检id" />
        </el-form-item>
        <el-form-item label="外观质量检查" prop="qualityAppearance">
          <el-input v-model="form.qualityAppearance" placeholder="请输入外观质量检查" />
        </el-form-item>
        <el-form-item label="尺寸大小检查" prop="qualityDimensiona">
          <el-input v-model="form.qualityDimensiona" placeholder="请输入尺寸大小检查" />
        </el-form-item>
        <el-form-item label="强度和耐性检查" prop="qualityStrength">
          <el-input v-model="form.qualityStrength" placeholder="请输入强度和耐性检查" />
        </el-form-item>
        <el-form-item label="织物结构检查" prop="qualityFabric">
          <el-input v-model="form.qualityFabric" placeholder="请输入织物结构检查" />
        </el-form-item>
        <el-form-item label="成分检查" prop="qualityComponent">
          <el-input v-model="form.qualityComponent" placeholder="请输入成分检查" />
        </el-form-item>
        <el-form-item label="质检数量" prop="qualityRawNum">
          <el-input v-model="form.qualityRawNum" placeholder="请输入质检数量" />
        </el-form-item>
        <el-form-item label="不合格数量" prop="qualityUnqualifiedNum">
          <el-input v-model="form.qualityUnqualifiedNum" placeholder="请输入不合格数量" />
        </el-form-item>
        <el-form-item label="化学物质检查" prop="qualityChemical">
          <el-input v-model="form.qualityChemical" placeholder="请输入化学物质检查" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>
  
<script>
import { listRaw, getRaw, delRaw, addRaw, updateRaw } from "@/api/quality/raw";

export default {
  name: "Raw",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 原料质检表格数据
      rawList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        qualityId: null,
        qualityAppearance: null,
        qualityDimensiona: null,
        qualityStrength: null,
        qualityFabric: null,
        qualityComponent: null,
        qualityRawNum: null,
        qualityUnqualifiedNum: null,
        qualityChemical: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询原料质检列表 */
    getList() {
      this.loading = true;
      listRaw(this.queryParams).then(response => {
        this.rawList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        qualityRawId: null,
        qualityId: null,
        qualityAppearance: null,
        qualityDimensiona: null,
        qualityStrength: null,
        qualityFabric: null,
        qualityComponent: null,
        qualityRawNum: null,
        qualityUnqualifiedNum: null,
        qualityChemical: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.qualityRawId)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加原料质检";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const qualityRawId = row.qualityRawId || this.ids
      getRaw(qualityRawId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改原料质检";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.qualityRawId != null) {
            updateRaw(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addRaw(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const qualityRawIds = row.qualityRawId || this.ids;
      this.$modal.confirm('是否确认删除原料质检编号为"' + qualityRawIds + '"的数据项？').then(function () {
        return delRaw(qualityRawIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => { });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('raw/raw/export', {
        ...this.queryParams
      }, `raw_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
  